VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{8D650141-6025-11D1-BC40-0000C042AEC0}#3.0#0"; "ssdw3b32.ocx"
Begin VB.Form frmCtaCteProfesional 
   BackColor       =   &H00FFFFFF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Cuenta Corriente Profesional"
   ClientHeight    =   6750
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7470
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6750
   ScaleWidth      =   7470
   Begin VB.CommandButton cmdImprimir 
      Appearance      =   0  'Flat
      BackColor       =   &H00FFFFFF&
      Caption         =   "Imprimir"
      Enabled         =   0   'False
      Height          =   390
      Left            =   6120
      MaskColor       =   &H00FFFFFF&
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   720
      Width           =   1140
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Datos"
      Height          =   855
      Left            =   120
      TabIndex        =   4
      Top             =   360
      Width           =   5775
      Begin VB.ComboBox cmbProf 
         Height          =   315
         Left            =   1200
         Style           =   2  'Dropdown List
         TabIndex        =   0
         Top             =   360
         Width           =   4455
      End
      Begin VB.Label Label3 
         BackColor       =   &H00FFFFFF&
         Caption         =   "Profesional:"
         Height          =   255
         Left            =   120
         TabIndex        =   5
         Top             =   360
         Width           =   975
      End
   End
   Begin MSComctlLib.ImageList ImageList1 
      Left            =   2280
      Top             =   0
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   11
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":0000
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":059A
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":0B34
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":10CE
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":1668
            Key             =   ""
         EndProperty
         BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":1C02
            Key             =   ""
         EndProperty
         BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":219C
            Key             =   ""
         EndProperty
         BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":2736
            Key             =   ""
         EndProperty
         BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":2CD0
            Key             =   ""
         EndProperty
         BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":326A
            Key             =   ""
         EndProperty
         BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCtaCteProfesional.frx":3804
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.Toolbar Toolbar1 
      Align           =   1  'Align Top
      Height          =   360
      Left            =   0
      TabIndex        =   3
      Top             =   0
      Width           =   7470
      _ExtentX        =   13176
      _ExtentY        =   635
      ButtonWidth     =   609
      ButtonHeight    =   582
      Appearance      =   1
      Style           =   1
      ImageList       =   "ImageList1"
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   6
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "Aceptar"
            Object.ToolTipText     =   "Aceptar (F5)"
            ImageIndex      =   5
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Enabled         =   0   'False
            Key             =   "Cancelar"
            Object.ToolTipText     =   "Cancelar (F8)"
            ImageIndex      =   6
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "Salir"
            Object.ToolTipText     =   "Salir (Esc)"
            ImageIndex      =   11
         EndProperty
         BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
      EndProperty
      BorderStyle     =   1
   End
   Begin SSDataWidgets_B.SSDBGrid Grilla 
      Height          =   5295
      Left            =   120
      TabIndex        =   1
      Top             =   1320
      Width           =   7200
      _Version        =   196616
      DataMode        =   2
      Col.Count       =   4
      BevelColorFace  =   16777215
      AllowUpdate     =   0   'False
      RowSelectionStyle=   2
      AllowRowSizing  =   0   'False
      AllowGroupSizing=   0   'False
      AllowGroupMoving=   0   'False
      AllowGroupSwapping=   0   'False
      AllowGroupShrinking=   0   'False
      AllowDragDrop   =   0   'False
      SelectTypeCol   =   0
      SelectTypeRow   =   1
      BackColorEven   =   12648447
      BackColorOdd    =   12640511
      RowHeight       =   423
      Columns.Count   =   4
      Columns(0).Width=   8123
      Columns(0).Caption=   "Obra Social"
      Columns(0).Name =   "Obra Social"
      Columns(0).CaptionAlignment=   2
      Columns(0).DataField=   "Column 0"
      Columns(0).DataType=   8
      Columns(0).FieldLen=   256
      Columns(1).Width=   3200
      Columns(1).Visible=   0   'False
      Columns(1).Caption=   "Efectivo"
      Columns(1).Name =   "Efectivo"
      Columns(1).Alignment=   1
      Columns(1).CaptionAlignment=   2
      Columns(1).DataField=   "Column 1"
      Columns(1).DataType=   8
      Columns(1).FieldLen=   256
      Columns(2).Width=   3200
      Columns(2).Visible=   0   'False
      Columns(2).Caption=   "Ordenes"
      Columns(2).Name =   "Ordenes"
      Columns(2).Alignment=   1
      Columns(2).CaptionAlignment=   2
      Columns(2).DataField=   "Column 2"
      Columns(2).DataType=   8
      Columns(2).FieldLen=   256
      Columns(3).Width=   3519
      Columns(3).Caption=   "Deuda"
      Columns(3).Name =   "Deuda"
      Columns(3).Alignment=   1
      Columns(3).CaptionAlignment=   2
      Columns(3).DataField=   "Column 3"
      Columns(3).DataType=   8
      Columns(3).FieldLen=   256
      _ExtentX        =   12700
      _ExtentY        =   9340
      _StockProps     =   79
      Caption         =   "Planilla de Deuda"
      BackColor       =   -2147483643
      BeginProperty PageFooterFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty PageHeaderFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
End
Attribute VB_Name = "frmCtaCteProfesional"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim con As New ConBaseDatos, cConcepto As String
Const decimales  As Integer = 2

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

Select Case Button.Key

    Case "Salir"
        Unload Me
    
    Case "Aceptar"
        If Control Then Exit Sub
        inHabilitar
        Imprimir ReplicarCaracter("0", LargoID, cmbProf.ItemData(cmbProf.ListIndex)), False
                
    Case "Cancelar"
        Habilitar
       
End Select

End Sub

Private Sub inHabilitar()

Toolbar1.Buttons.Item(2).Enabled = False
Toolbar1.Buttons.Item(3).Enabled = True
cmdImprimir.Enabled = True
cmbProf.Enabled = False
cmbProf.BackColor = &H80000005

End Sub

Private Sub Habilitar()

Toolbar1.Buttons.Item(2).Enabled = True
Toolbar1.Buttons.Item(3).Enabled = False
cmdImprimir.Enabled = False
cmbProf.Enabled = True
cmbProf.ListIndex = -1
Grilla.RemoveAll
cmbProf.SetFocus

End Sub

Private Function Control() As Boolean

Control = False
If cmbProf.ListIndex = -1 Then
    MsgBox "Seleccione un profesional", vbCritical, "Error de datos"
    Control = True
    cmbProf.SetFocus
End If

If Control Then Exit Function

Dim datos() As String, dato() As String

con.AbrirRegistros "select * from parametros where parametro='0000000002'", Consulta
If Not con.Registros.EOF Then
    datos = Split(con.Registros("datos"), "<||>")
    
    dato = Split(datos(1), ":")
    cConcepto = ReplicarCaracter("0", LargoID, dato(1))
Else
    MsgBox "No hay un concepto seleccionado en parametros de fondos" & vbCrLf & "Para pago de profesional", vbCritical, "Error Datos"
    Control = True
End If
con.CerrarRegistros

End Function

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
    Case 27 'Escape "Salir"
        If Toolbar1.Buttons(5).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(5)
        
    Case 112 'F1 "Ayuta"
        frmPrincipal.manual_Click
        
    Case 116 'F5 "Aceptar"
        If Toolbar1.Buttons(2).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(2)
    
    Case 119 'F8 "Cancelar"
        If Toolbar1.Buttons(3).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(3)
        
End Select

End Sub

Private Sub Form_Load()

Abrir Me
Me.Icon = frmPrincipal.Icon

con.AbrirRegistros "select profesional,  apellido + ', ' + nombre + ' - ' + 'Mat.Prof.: ' + matricula_profesional as nombre from profesionales where activo = 1 order by apellido,nombre", Consulta
Do While Not con.Registros.EOF
    cmbProf.AddItem DesEditar(con.Registros("nombre"))
    cmbProf.ItemData(cmbProf.NewIndex) = CInt(con.Registros("profesional"))
    con.Registros.MoveNext
    DoEvents
Loop
con.CerrarRegistros
cmbProf.ListIndex = -1

End Sub

Private Sub cmbProf_GotFocus()

cmbProf.BackColor = &HFFFFC0

End Sub

Private Sub cmbProf_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
    Case 13
        'SendKeys "{TAB}"
        KeyAscii = 0

    Case 8, 32
        cmbProf.ListIndex = -1

End Select

End Sub

Private Sub cmbProf_LostFocus()

cmbProf.BackColor = &H80000005

End Sub

Private Sub cmdImprimir_Click()

Imprimir ReplicarCaracter("0", LargoID, cmbProf.ItemData(cmbProf.ListIndex)), True

End Sub

Private Sub Imprimir(prof As String, Imprime As Boolean)

Dim i As Integer, dato As String, InfExel As Object, datoTemp As String
Dim totE As Double, Linea As Integer, totO As Double, totD As Double

dato = "select isnull(o.codigo+' - '+o.nombre,'Sin Obra Social') as obra_social," & _
        " isnull(sum(case when ci.efectivo=1 and ci.tipo='Ingreso' then ci.cantidad*ci.ingreso1 when ci.concepto='" & cConcepto & "' and ci.efectivo=1 and ci.tipo='Egreso' then ci.cantidad*ci.egreso*-1 else 0 end),0)+" & _
        " isnull((select sum(a.ajuste) from ajustes_saldos_fondos a where a.profesional='" & ReplicarCaracter("0", LargoID, cmbProf.ItemData(cmbProf.ListIndex)) & "' and a.obra_social=ci.obra_social),0) as efectivo," & _
        " isnull(sum(case when ci.efectivo=0 and ci.tipo='Ingreso' then ci.cantidad*ci.ingreso1 when ci.concepto='" & cConcepto & "' and ci.efectivo=0 and ci.tipo='Egreso' then ci.cantidad*ci.egreso*-1 else 0 end),0) as ordenes," & _
        " isnull(sum(case when ci.efectivo=1 and ci.tipo='Ingreso' then ci.cantidad*ci.ingreso1 when ci.concepto='" & cConcepto & "' and ci.efectivo=1 and ci.tipo='Egreso' then ci.cantidad*ci.egreso*-1 else 0 end),0)+" & _
        " isnull((select sum(a.ajuste) from ajustes_saldos_fondos a where a.profesional='" & ReplicarCaracter("0", LargoID, cmbProf.ItemData(cmbProf.ListIndex)) & "' and a.obra_social=ci.obra_social),0)+" & _
        " isnull(sum(case when ci.efectivo=0 and ci.tipo='Ingreso' then ci.cantidad*ci.ingreso1 when ci.concepto='" & cConcepto & "' and ci.efectivo=0 and ci.tipo='Egreso' then ci.cantidad*ci.egreso*-1 else 0 end),0) as deuda" & _
        " from cajas_items ci" & _
        " left join obras_sociales o on o.obra_social=ci.obra_social" & _
        " where ci.profesional='" & prof & "' and ci.estado='Activo'" & _
        " group by isnull(o.codigo+' - '+o.nombre,'Sin Obra Social'),o.nombre,ci.obra_social" & _
        " having isnull(sum(case when ci.efectivo=1 and ci.tipo='Ingreso' then ci.cantidad*ci.ingreso1 when ci.efectivo=1 and ci.tipo='Egreso' then ci.cantidad*ci.egreso*-1 else 0 end),0)+" & _
        " isnull((select sum(a.ajuste) from ajustes_saldos_fondos a where a.profesional='" & ReplicarCaracter("0", LargoID, cmbProf.ItemData(cmbProf.ListIndex)) & "' and a.obra_social=ci.obra_social),0)+" & _
        " isnull(sum(case when ci.efectivo=0 and ci.tipo='Ingreso' then ci.cantidad*ci.ingreso1 when ci.efectivo=0 and ci.tipo='Egreso' then ci.cantidad*ci.egreso*-1 else 0 end),0)<>0" & _
        " order by 1"

con.AbrirRegistros dato, Consulta

Grilla.RemoveAll
If con.Registros.EOF Then
    MsgBox "No hay deuda en el profesional: " & cmbProf.Text, vbExclamation, "Planilla de Deuda"
    Habilitar
    Exit Sub
End If

'cargo la grilla
Grilla.Redraw = False
Do While Not con.Registros.EOF
    dato = ""
    For i = 0 To Grilla.Cols - 1
        datoTemp = ""
        If IsNull(con.Registros(i)) Then
            datoTemp = ""
        Else
            datoTemp = con.Registros(i)
            Select Case con.Registros(i).Name
                Case "efectivo", "ordenes", "deuda"
                    datoTemp = FormatoDecimales(datoTemp, decimales)
            End Select
        End If
        dato = dato & DesEditar((datoTemp)) & vbTab
        DoEvents
    Next i
    Grilla.AddItem dato
    totE = totE + con.Registros("efectivo")
    totO = totO + con.Registros("ordenes")
    totD = totD + con.Registros("deuda")
    con.Registros.MoveNext
    
    If con.Registros.EOF Then
        'inserto un registro en blanco
        dato = ""
        For i = 0 To Grilla.Cols - 1
            dato = dato & "" & vbTab
            DoEvents
        Next i
        Grilla.AddItem dato
        'inserto total general
        dato = "TOTAL GENERAL" & vbTab & FormatoDecimales(totE, decimales) & vbTab & FormatoDecimales(totO, decimales) & vbTab & FormatoDecimales(totD, decimales)
        Grilla.AddItem dato
    End If
    DoEvents
Loop
con.CerrarRegistros

Grilla.Redraw = True

'si imprime
If Not Imprime Then
    Exit Sub
End If

If Not ExisteExcel Then
    MsgBox "Debe estar instalado MS Excel", vbCritical, "Operacion cancelada"
    Exit Sub
End If

Set InfExel = CreateObject("Excel.application")

'Agrega un nuevo Libro
InfExel.Workbooks.Add

'todas las celdas tipo texto
InfExel.Cells.Select
InfExel.Selection.NumberFormat = "@"

'hace que excel se vea
'InfExel.Visible = True

'cabecera
InfExel.Cells(2, 3).Formula = "PLANILLA DE DEUDA"
InfExel.Cells(2, 3).Font.Size = 12
InfExel.Range("C2").Select
InfExel.Selection.Font.Bold = True

InfExel.Cells(3, 6).Formula = "Fecha:"
InfExel.Cells(3, 6).HorizontalAlignment = -4152
InfExel.Cells(3, 7).Formula = Format(Fecha_Server, "dd/mm/yyyy")
InfExel.Cells(3, 7).HorizontalAlignment = -4131

InfExel.Cells(4, 2).Formula = "Profesional:"
InfExel.Cells(4, 2).HorizontalAlignment = -4152
InfExel.Cells(4, 3).Formula = cmbProf.Text
InfExel.Cells(4, 3).HorizontalAlignment = -4131
InfExel.Range("C4").Select
InfExel.Selection.Font.Underline = 2


'columnas
InfExel.Cells(6, 2).Formula = "Obra Social"
InfExel.Cells(6, 5).Formula = "Efectivo"
InfExel.Cells(6, 6).Formula = "Ordenes"
InfExel.Cells(6, 7).Formula = "Deuda"
InfExel.Range("B6:G6").Select
InfExel.Selection.Font.Bold = True
InfExel.Selection.HorizontalAlignment = -4108

'detalle
Grilla.Redraw = False
Linea = 7
Grilla.MoveFirst
For i = 0 To Grilla.Rows - 1
    InfExel.Cells(Linea, 2).Formula = Grilla.Columns(0).CellText(Grilla.Bookmark)
    InfExel.Cells(Linea, 2).HorizontalAlignment = -4131
    
    InfExel.Cells(Linea, 5).Formula = Grilla.Columns(1).CellText(Grilla.Bookmark)
    InfExel.Cells(Linea, 5).HorizontalAlignment = -4152
    
    InfExel.Cells(Linea, 6).Formula = Grilla.Columns(2).CellText(Grilla.Bookmark)
    InfExel.Cells(Linea, 6).HorizontalAlignment = -4152
    
    InfExel.Cells(Linea, 7).Formula = Grilla.Columns(3).CellText(Grilla.Bookmark)
    InfExel.Cells(Linea, 7).HorizontalAlignment = -4152
    
    Grilla.MoveNext
    Linea = Linea + 1
    DoEvents
Next i
Grilla.MoveFirst
Grilla.Redraw = True

InfExel.Range("B" & Linea - 1 & ":G" & Linea - 1).Select
InfExel.Selection.Font.Bold = True


InfExel.Range("G" & Linea - 1).Select
InfExel.Selection.Borders(5).LineStyle = -4142
InfExel.Selection.Borders(6).LineStyle = -4142
With InfExel.Selection.Borders(7)
    .LineStyle = 1
    .Weight = 2
    .ColorIndex = -4105
End With
With InfExel.Selection.Borders(8)
    .LineStyle = 1
    .Weight = 2
    .ColorIndex = -4105
End With
With InfExel.Selection.Borders(9)
    .LineStyle = 1
    .Weight = 2
    .ColorIndex = -4105
End With
With InfExel.Selection.Borders(10)
    .LineStyle = 1
    .Weight = 2
    .ColorIndex = -4105
End With

InfExel.Range("A1").Select

'margenes a cero
InfExel.ActiveSheet.PageSetup.LeftMargin = InfExel.Application.InchesToPoints(0)
InfExel.ActiveSheet.PageSetup.RightMargin = InfExel.Application.InchesToPoints(0)
InfExel.ActiveSheet.PageSetup.TopMargin = InfExel.Application.InchesToPoints(0)
InfExel.ActiveSheet.PageSetup.BottomMargin = InfExel.Application.InchesToPoints(0)
InfExel.ActiveSheet.PageSetup.HeaderMargin = InfExel.Application.InchesToPoints(0)
InfExel.ActiveSheet.PageSetup.FooterMargin = InfExel.Application.InchesToPoints(0)

'imprimo el excel directo a la impresora predeterminada
'InfExel.ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

'imprimo el excel en la impresora seleccionada
Load frmImpresora
frmImpresora.Show 1
If ImpresoraSeleccionada <> "" Then
    InfExel.ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
    ImpresoraSeleccionada, Collate:=True
End If

'para que no pregunte si se quiere guardar los cambios
InfExel.ActiveWorkbook.Saved = True

'cierro el excel
InfExel.Workbooks.Close
InfExel.Quit

Set InfExel = Nothing

End Sub
